package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.R;
import com.itheima.reggie.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b><code>OrdersController</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 29/06/2024 20:50.
 *
 * @author yanjr
 * @since reggie_take_out
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    /**
     * 用户下单
     * @param orders 订单信息
     * @return 是否成功
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        return ordersService.submit(orders);
    }

    /**
     * 查看订单
     * @param page 当前页
     * @param pageSize 每页显示条数
     * @return 分页信息
     */
    @GetMapping("/userPage")
    public R<Page<Orders>> userPage(@RequestParam(name = "page") int page,
                                    @RequestParam(name = "pageSize") int pageSize) {
        return ordersService.userPage(page, pageSize);
    }

}
